<template>
    <div></div>
</template>

<script>
import { REDIRECT_TYPE } from '@constants/types';
import { repalceTo } from '@common/utils';
import { setUserMemberIdCookie, setUserTokenCookie,
    setUiMode, setUiTheme, setUiStyleMode, setLocationValue, setBrandNameCookie,
    setBrandIdCookie, setBrandOperationMode, setCartGoodsIds } from '@biztools/info';

export default {
    name: 'BilinMiniRedirect', // 小程序跳转页面
    components: {},
    data() {
        return {
            query: '',
        };
    },
    created() {
        const { memberToken, memberId, mode, theme, styleMode, redirectType,
            goodsId, goodsIds, latitude, longitude, storeId, title, orderNumber,
            operationMode, brandId, brandName, cartIds } = this.$route.query;
        setUserMemberIdCookie(memberId);
        setUserTokenCookie(memberToken);
        setBrandIdCookie(brandId);
        setBrandNameCookie(brandName);
        setBrandOperationMode(operationMode);
        setCartGoodsIds(cartIds);

        mode && setUiMode(mode);
        theme && setUiTheme(`#${theme}`);
        styleMode && setUiStyleMode(styleMode);

        setLocationValue({
            latitude,
            longitude,
        });
        let param = {};

        switch(redirectType) {
        case REDIRECT_TYPE.cart:
            repalceTo('shop/bag');
            break;
        case REDIRECT_TYPE.goodsDetail:
            if (storeId) {
                param = {
                    storeId,
                };
            }
            repalceTo(`shop/detail/${goodsId}`, param);
            break;
        case REDIRECT_TYPE.special:
            repalceTo(`shop/special/${storeId}`);
            break;
        case REDIRECT_TYPE.address:
            repalceTo('shop/address');
            break;
        case REDIRECT_TYPE.prefecture:
            repalceTo('shop/prefecture', {
                goodsIds: goodsIds || '',
                title,
            });
            break;
        case REDIRECT_TYPE.classify:
            repalceTo('shop/classify');
            break;
        case REDIRECT_TYPE.orderList:
            repalceTo('shop-order/list');
            break;
        case REDIRECT_TYPE.orderDetail:
            repalceTo(`shop-order/detail/${orderNumber}`);
            break;
        }
    },
};
</script>

<style lang="less">

</style>
